package com.tju.ocean_ecology_website.dto;

import com.tju.ocean_ecology_website.entity.User;
import com.tju.ocean_ecology_website.entity.VolunteerInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * 志愿者DTO，包含用户信息和志愿者信息
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class VolunteerDTO {
    // 用户信息
    private Long id;
    private String username;
    private String name;
    private String email;
    private String phone;
    private String avatar;
    private Integer status;
    private Date createTime;

    // 志愿者信息
    private Long volunteerId;
    private String realName;
    private Integer gender;
    private Date birthDate;
    private String region;
    private String skills;
    private Integer volunteerHours;

    /**
     * 从用户和志愿者信息构建DTO
     */
    public static VolunteerDTO fromUserAndVolunteerInfo(User user, VolunteerInfo volunteerInfo) {
        VolunteerDTO dto = new VolunteerDTO();

        // 设置用户信息
        if (user != null) {
            dto.setId(user.getId());
            dto.setUsername(user.getUsername());
            dto.setName(user.getName());
            dto.setEmail(user.getEmail());
            dto.setPhone(user.getPhone());
            dto.setAvatar(user.getAvatar());
            dto.setStatus(user.getStatus());
            dto.setCreateTime(user.getCreateTime());
        }

        // 设置志愿者信息
        if (volunteerInfo != null) {
            dto.setVolunteerId(volunteerInfo.getId());
            dto.setRealName(volunteerInfo.getRealName());
            dto.setGender(volunteerInfo.getGender());
            dto.setBirthDate(volunteerInfo.getBirthDate());
            dto.setRegion(volunteerInfo.getRegion());
            dto.setSkills(volunteerInfo.getSkills());
            dto.setVolunteerHours(volunteerInfo.getVolunteerHours());
        }

        return dto;
    }
}
